//
//  ZMYSettingCollectionViewCell.m
//  奇阅
//
//  Created by 奇阅科技 on 14-10-27.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "ZMYSettingCollectionViewCell.h"
#import "ZMYSettingCollectionViewTableViewCell.h"
#import "Config.h"
#import "MyRechargeRecordTableViewController.h"
#import "MyTouchIdDemo.h"
#import "MyEverydayTaskViewController.h"
#import "MyExchangeViewController.h"
#import "BookShoppingWebViewController.h"
#import "PayWebView.h"
#import "ZMYForgetPasswdViewController.h"
@interface ZMYSettingCollectionViewCell()
{
    NSMutableArray *dataArray;
    NSMutableArray *titleArray;
}
@end
@implementation ZMYSettingCollectionViewCell
-(void)initDataArray{
    UserAccount *user = [UserAccount currentAccount];
    NSInteger i=1;
    if (user.uid&&user.mobile.length<1) {
        i = 0;
    }
    NSArray *titlArray = @[@"绑定手机送200阅币",@"充值",@"充值记录",@"积分兑换阅币",@"赚取积分",@"每日任务"];
    dataArray = [NSMutableArray new];
    titleArray = [NSMutableArray new];
    for (; i<6; i++) {
        [dataArray addObject:[NSString stringWithFormat:@"settingCell%ld",(long)i]];
        [titleArray addObject:[titlArray objectAtIndex:i]];
    }
    [self.tableView reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZMYSettingCollectionViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZMYSettingCollectionViewTableViewCell" forIndexPath:indexPath];
    cell.settingTitleLabel.text = titleArray[indexPath.row];
    cell.settingImageView.image = [UIImage imageNamed:dataArray[indexPath.row]];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *titleStr = titleArray[indexPath.row];
    if ([titleStr isEqualToString:@"绑定手机送200阅币"]) {
        [MobClick event:@"2009"];
        ZMYForgetPasswdViewController *view = [[UIStoryboard storyboardWithName:@"BookRack" bundle:nil] instantiateViewControllerWithIdentifier:@"ZMYForgetPasswdViewController"];
        view.isBindingPhone = YES;
        if ([self.delegate respondsToSelector:@selector(pushToViewController:)]) {
            [self.delegate pushToViewController:view];
        }
        return;
    }
    if ([titleStr isEqualToString:@"充值"]) {
        UserAccount *user = [UserAccount currentAccount];
        if (!user) {
            [AppDelegate showHUDAndHide:@"请登录后继续操作" view:[AppDelegate delegate].window];
            return;
        }
        PayWebView *view = [[[NSBundle mainBundle]loadNibNamed:@"PayWebView" owner:self options:nil] lastObject];
        //api.local.com/web/qy_apple.php?a=apple_order_web&uid=85623598&token=062dd8cb06
        view.webUrl = [NSString stringWithFormat:@"http://%@/web/qy_apple.php?a=apple_order_web&uid=%@&token=%@&srcid=iOS&ct=iOS&pay_way=iOS",SERVER,user.uid,user.token];
        [view showView];
        return;
    }
    if ([titleStr isEqualToString:@"充值记录"]) {
        MyRechargeRecordTableViewController *view = [[UIStoryboard storyboardWithName:@"BookShop" bundle:nil] instantiateViewControllerWithIdentifier:@"MyRechargeRecordTableViewController"];
        if ([self.delegate respondsToSelector:@selector(pushToViewController:)]) {
            [self.delegate pushToViewController:view];
        }
        return;
    }
    if ([titleStr isEqualToString:@"积分兑换阅币"]) {
        MyExchangeViewController *view = [[UIStoryboard storyboardWithName:@"BookShop" bundle:nil] instantiateViewControllerWithIdentifier:@"MyExchangeViewController"];
        if ([self.delegate respondsToSelector:@selector(pushToViewController:)]) {
            [self.delegate pushToViewController:view];
        }
        return;
    }
    if ([titleStr isEqualToString:@"赚取积分"]) {
        BookShoppingWebViewController * childView = [[UIStoryboard storyboardWithName:@"BookShop" bundle:nil] instantiateViewControllerWithIdentifier:@"BookShoppingWebViewController"];
        childView.titleStr = @"赚取积分";
        childView.urlStr = @"http://dataapi.yuewen.cc/web/qy_about.php?a=zhuanyuebi";
        childView.isPushByNav = YES;
        [MobClick event:@"2018"];
        childView.webView.scrollView.bounces = NO;
        if ([self.delegate respondsToSelector:@selector(pushToViewController:)]) {
            [self.delegate pushToViewController:childView];
        }
        return;
    }
    if ([titleStr isEqualToString:@"每日任务"]) {
        MyEverydayTaskViewController *view = [[UIStoryboard storyboardWithName:@"BookShop" bundle:nil] instantiateViewControllerWithIdentifier:@"MyEverydayTaskViewController"];
        if ([self.delegate respondsToSelector:@selector(pushToViewController:)]) {
            [self.delegate pushToViewController:view];
        }
        return;
    }
}

@end
